home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-01-06 | 5.1 KB | 213 lines | [TEXT/KAHL] |
- /* Prototypes */
- void MakeIndexedPict2(void);
- void MakeDirectPict2(void);
- void MakeHalftone(void);
- PicHandle CreatePICT2( PixMap *srcBits, Rect *srcRect, Rect *dstRect, short mode );
- PicHandle HalftonePixMap(PixMapHandle hSource, Boolean qdPixMap, short Resolution);
-
- #define TESTROWBYTES 20
-
- /* external System version global */
- extern short gSystemVersion;
-
-
- void
- MakeIndexedPict2(void)
- {
- PicHandle myPic;
- PixMap srcBits;
- Rect myRect, offBounds = {0, 0, 200, 200};
- long myErr;
- short * bitsPtr;
- short iii;
-
-
- /* Build a nice PixMap */
- srcBits.baseAddr = (Ptr)NewPtr( TESTROWBYTES*4 ); /* rowbytes = TESTROWBYTES, height = 4 */
- /* Cheesy error checking */
- if(srcBits.baseAddr == nil) { SysBeep(10); return; }
- srcBits.rowBytes = TESTROWBYTES | 0x8000; /* pixmap */
- srcBits.bounds.top = 0;
- srcBits.bounds.left = 0;
- srcBits.bounds.bottom = 4;
- srcBits.bounds.right = TESTROWBYTES;
- srcBits.pmVersion = 0;
- srcBits.packType = 0;
- srcBits.packSize = 0;
- srcBits.hRes = 0x480000; /* 72, fixed point */
- srcBits.vRes = 0x480000;
- srcBits.pixelType = 0;
- srcBits.pixelSize = 8;
- srcBits.cmpCount = 1;
- srcBits.cmpSize = 8;
- srcBits.planeBytes = 0;
- srcBits.pmTable = GetCTable( 8 );
- /* Cheesy error checking */
- if(srcBits.pmTable == nil) {SysBeep(10); DisposPtr(srcBits.baseAddr); return;}
- srcBits.pmReserved = 0;
-
- /* Load an image */
- bitsPtr = (short *) srcBits.baseAddr;
- for( iii = TESTROWBYTES*2; iii > 0; iii-- )
- *bitsPtr++ = iii*0x105;
-
- SetRect( &myRect, 0, 0, TESTROWBYTES, 4 ); /*left, top, right, bottom */
-
- myPic = CreatePICT2( &srcBits, &myRect, &offBounds, ditherCopy );
- if( !myPic )
- {
- SysBeep(10);
- DisposPtr(srcBits.baseAddr);
- DisposCTable(srcBits.pmTable);
- return;
- }
-
- // DrawPicture( myPic, &(**myPic).picFrame);
- myRect = qd.thePort->portRect; /*left, top, right, bottom */
- DrawPicture( myPic, &myRect);
-
- ZeroScrap();
- myErr = PutScrap( GetHandleSize( myPic ), 'PICT', *myPic );
-
- DisposCTable( srcBits.pmTable ); /* Dispose of color table */
- DisposPtr( srcBits.baseAddr );
- DisposHandle( (Handle) myPic );
- }
-
- void
- MakeDirectPict2(void)
- {
- PicHandle myPic;
- PixMap srcBits;
- Rect myRect, offBounds = {0, 0, 200, 200};
- long myErr;
- short * bitsPtr;
- short iii;
-
-
- /* Build a nice PixMap */
- srcBits.baseAddr = (Ptr)NewPtr( TESTROWBYTES*4*4 ); /* rowbytes = TESTROWBYTES, height = 4, 4bytes/pixel */
- /* Cheesy error checking */
- if(srcBits.baseAddr == nil) { SysBeep(10); return; }
- srcBits.rowBytes = (TESTROWBYTES *4) | 0x8000; /* pixmap */
- srcBits.bounds.top = 0;
- srcBits.bounds.left = 0;
- srcBits.bounds.bottom = 4;
- srcBits.bounds.right = TESTROWBYTES;
- srcBits.pmVersion = 0;
- srcBits.packType = 0;
- srcBits.packSize = 0;
- srcBits.hRes = 0x480000;
- srcBits.vRes = 0x480000;
- srcBits.pixelType = 16;
- srcBits.pixelSize = 32;
- srcBits.cmpCount = 3;
- srcBits.cmpSize = 8;
- srcBits.planeBytes = 0;
- srcBits.pmTable = 0; // No color table in a direct PixMap
- srcBits.pmReserved = 0;
-
- bitsPtr = (short *) srcBits.baseAddr;
- for( iii = TESTROWBYTES*2*4; iii > 0; iii-- )
- *bitsPtr++ = iii*0x105;
-
- SetRect( &myRect, 0, 0, TESTROWBYTES, 4 ); /*left, top, right, bottom */
-
- myPic = CreatePICT2( &srcBits, &myRect, &offBounds, ditherCopy );
- if( !myPic )
- {
- SysBeep(10);
- DisposPtr(srcBits.baseAddr);
- return;
- }
-
- // DrawPicture( myPic, &(**myPic).picFrame);
- myRect = qd.thePort->portRect; /*left, top, right, bottom */
- DrawPicture( myPic, &myRect);
-
- ZeroScrap();
- myErr = PutScrap( GetHandleSize( myPic ), 'PICT', *myPic );
-
- DisposPtr(srcBits.baseAddr);
- DisposHandle( (Handle) myPic );
- }
-
-
- void
- MakeHalftone()
- {
- PicHandle myPic;
- PicHandle myPic1;
- PixMap srcBits;
- Rect myRect;
- Rect thisRect;
- long myErr;
- short * bitsPtr;
- short iii;
- PixMapHandle myPixMapHandle2;
- GWorldPtr myOffGWorld2;
- RGBColor saveRGB;
- RGBColor myRGB;
- GDHandle oldGD;
- GWorldPtr oldGW;
-
- SetRect( &myRect, 0, 0, 256, 256 );
- if( NewGWorld( &myOffGWorld2, 32, &myRect, 0, 0, 0 ) == noErr )
- {
- GetForeColor( &saveRGB );
- GetGWorld( &oldGW,&oldGD );
- SetGWorld( myOffGWorld2,nil );
-
- if(gSystemVersion < 0x0700)
- myPixMapHandle2 = myOffGWorld2->portPixMap; /* -----pre-7.0 */
- else
- myPixMapHandle2 = GetGWorldPixMap( myOffGWorld2 ); /* 7.0 only */
-
- LockPixels( myPixMapHandle2 );
- EraseRect( &myRect );
- #define NUMDIVS 10
- for( iii = 0; iii <= NUMDIVS; iii++ )
- {
- myRGB.red = myRGB.green = myRGB.blue =((long)iii*255/NUMDIVS) << 8;
- RGBForeColor( &myRGB );
- SetRect( &thisRect, iii*myRect.right/(NUMDIVS+1), 0, (iii+1)*myRect.right/(NUMDIVS+1), myRect.bottom );
- PaintRect( &thisRect );
- }
-
- myRGB.red = myRGB.green = myRGB.blue = 0;
- PenMode( srcXor );
- RGBForeColor( &myRGB );
- FrameRect( &myRect );
-
- SetGWorld( oldGW, oldGD );
- RGBForeColor( &saveRGB );
- }
- else
- {
- SysBeep(10);
- return;
- }
- srcBits = **myPixMapHandle2;
-
- myPic = HalftonePixMap( myPixMapHandle2, true, 72 );
- if( !myPic )
- {
- SysBeep(10);
- UnlockPixels( myPixMapHandle2 );
- DisposeGWorld( myOffGWorld2 );
- return;
- }
- DrawPicture( myPic, &(**myPic).picFrame );
-
- /* Add Pict to clipboard */
- ZeroScrap();
- myErr = PutScrap( GetHandleSize( myPic ), 'PICT', *myPic );
-
- /* Clean up */
- UnlockPixels( myPixMapHandle2 );
- DisposeGWorld( myOffGWorld2 );
- DisposHandle( (Handle) myPic );
- }
-
-
-